using System;
using System.Collections.Generic;
using System.Text;

namespace MCromwell.StaffIntranet.DTO
{
    public class NotificationDTO
    {
        IDictionary<string, ErrorDTO> errors = new Dictionary<string, ErrorDTO>();
        IDictionary<string, InfoDTO> infos = new Dictionary<string, InfoDTO>();

        public void AddError(string errorId, string message)
        {
            if (!errors.ContainsKey(errorId))
                errors.Add(errorId, new ErrorDTO(errorId, message));
        }

        public ErrorDTO GetError(string errorId)
        {
            if (errors.ContainsKey(errorId))
                return errors[errorId];
            else
                return ErrorDTO.Empty;
        }

        public bool ErrorExists(string errorId)
        {
            return (errors.ContainsKey(errorId));
        }

        public bool HasErrors
        {
            get {return (errors.Count > 0);}
        }

        public IList<ErrorDTO> Errors
        {
            get { return new List<ErrorDTO>(errors.Values).AsReadOnly(); }
        }

        public void AddInfo(string infoId, string message)
        {
            if (!infos.ContainsKey(infoId))
                infos.Add(infoId, new InfoDTO(infoId, message));
        }

        public InfoDTO GetInfo(string infoId)
        {
            if (infos.ContainsKey(infoId))
                return infos[infoId];
            else
                return InfoDTO.Empty;
        }

        public bool HasInfos
        {
            get { return (infos.Count > 0); }
        }

        public IList<InfoDTO> Infos
        {
            get { return new List<InfoDTO>(infos.Values).AsReadOnly(); }
        }

        public bool InfoExists(string infoId)
        {
            return (infos.ContainsKey(infoId));
        }

        public static NotificationDTO Empty
        {
            get
            {
                return new NotificationDTO();
            }
            
        }
    }
}
